local app = require "app"
local game = app.game.running

local M = game.ui.element()

function M:ctor(data, index)
    self.data = data
    self.index = index
    self.res = "club.threecard.baccaratlib/ui/common.b:PlayerListItem"

    local AvatarIcon = require "ui.Common.AvatarIcon"
    self.avatar_icon = AvatarIcon.new()
end

function M:on_load()
    self:super("on_load")
    self.avatar_icon:load()
    self.avatar_icon:set_parent(self.head_root, false)
    self.avatar_icon:set_head(self.data.head)
    self.avatar_icon:set_flag(self.data.country)
    self.name_txt.text = self.data.name
    self.chip_txt.text = app.i18n.number(self.data.chip, "chip2")
    if self.index <= 3 then
        self.rank_1:SetActive(self.index == 1)
        self.rank_2:SetActive(self.index == 2)
        self.rank_3:SetActive(self.index == 3)
        self.rank_value_txt.gameObject:SetActive(false)
    else
        self.rank_value_txt.gameObject:SetActive(true)
        self.rank_1:SetActive(false)
        self.rank_2:SetActive(false)
        self.rank_3:SetActive(false)
        self.rank_value_txt.text = string.format("NO.%s", self.index)
    end

    self.bet_times_txt.text = string.format("%s局", self.data.bet_times)
    self.win_times_txt.text = string.format("%s局", self.data.win_times)
end

function M:on_release()
    self:super("on_release")
    self.avatar_icon:release()
end

return M